import request from "./request";

// 登录
export const reqLogin = (data) => request ({url: '/login', method: 'post', data})

// 获取一级或某个二级分类列表manage/category/list
export const reqCategoryList = ({parentId}) => request ({url: '/manage/category/list/', method: 'get',params: {parentId}})
// export const reqCategoryList = (parentId) => request ({url: `/manage/category/list/?parentId=${parentId}`, method: 'get'})
// 添加分类 manage/category/add
export const reqAddCategory = ({parentId,categoryName}) => request ({url: '/manage/category/add', method: 'post', data: {parentId,categoryName}})
// 更新品类名称manage/category/update
export const reqUpdateCategory = ({categoryId,categoryName}) => request ({url: '/manage/category/update', method: 'post', data: {categoryId,categoryName}})

// 获取商品分类列表
export const reqProductList = (pageNum, pageSize) => request ({url: '/manage/product/list', method: 'get',params: {pageNum, pageSize}})
// 搜索商品
export const reqSearchProduct = (pageNum, pageSize, searchType, searchName) => request ({url: '/manage/product/search', method: 'get',params: {pageNum, pageSize, [searchType]: searchName}})
// 商品详情获取对应分类
export const reqCategoryName = (categoryId) => request ({url:'/manage/category/info', method: 'get',params: {categoryId}})
// 商品状态post manage/product/updateStatus 
export const reqProductStatus = (productId, status) => request ({url: 'manage/product/updateStatus', method: 'post', data: {productId, status}})
// 删除商品图片
export const reqDeleteImg = (name) => request ({url:'/manage/img/delete', method: 'post',data: {name}})
// 添加或修改商品
export const reqAddOrUpdateProduct = (product) => request ({url:'/manage/product/'+ (product._id? 'update' : 'add'), method: 'post',data: product})

// 获取角色列表
export const reqRoleList = () => request ({url:'/manage/role/list', method: 'get'})
// 添加角色
export const reqAddRoleList = (roleName) => request ({url:'/manage/role/add', method: 'post', data: {roleName}})
// 更新角色权限
export const reqUpdateRole = (role) => request ({url:'/manage/role/update', method: 'post', data: role})

// 所有用户列表
export const reqGetUserlist = () => request ({url: '/manage/user/list', method: 'get'})

// 删除用户
export const reqDeleteUser = (userId) => request ({url: '/manage/user/delete', method: 'post', data: {userId}})

// 添加用户
export const reqAddOrUpdateUser = (user) => request ({url: '/manage/user/'+(user._id? 'update': 'add'), method: 'post', data: user})